package com.demo.controller;

import com.demo.entity.Flower;
import com.demo.service.FlowerService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/flower")
public class FlowerController {
    @Autowired
    private FlowerService service;

    @GetMapping
    public List<Flower> selectAll() {
        return service.selectAll();
    }

    @GetMapping(params = "name")
    public List<Flower> selectByname(String name) {
        return service.selectByname(name);
    }
    @GetMapping("{id}")
    public Flower selectById(@PathVariable String id) {
        return service.selectById(Integer.parseInt(id));
    }

    @DeleteMapping("{id}")
    public int deleteById(@PathVariable String id) {
        return service.deleteById(Integer.parseInt(id));
    }

    @PostMapping
    public int insertFlower(@RequestBody Flower flowers) {
        return service.insertFlower(flowers);
    }
    @PutMapping  // 修改
    public int updateStudent(@RequestBody Flower flowers) {
        return service.updateFlower(flowers);
    }
}
